package com.hp.bon.sgw.stdbss30;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.hp.bon.sgw.stdbss30.bizSlot.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hp.bon.sgw.stdbss30.bizSlotOutQuery.BillDetailQueryYXHB9BizSlot;
import com.hp.bon.sgw.stdbss30.bizSlotOutside.CommonDynQueryHBBizSlot;
import com.hp.bon.sgw.stdbss30.bizSlotOutside.CreditQueryYXHB9BizSlot;
import com.hp.bon.sgw.stdbss30.bizSlotOutside.DayCardUnBlockBizSlot;
import com.hp.bon.sgw.stdbss30.bizSlotOutside.QryBalOweBizSlot;
import com.hp.bon.sgw.stdbss30.bizSlotOutside.QueryHomeAreaByAccNbrBizSlot;
import com.hp.bon.sgw.stdbss30.bizSlotOutside.QueryServBizSlot;
import com.hp.bon.sgw.stdbss30.bizSlotOutside.ReturnBalanceDetailYXHB9BizSlot;
import com.hp.bon.sgw.stdbss30.bizSlotOutside.ReturnBalanceYXHB9BizSlot;
import com.hp.bon.sgw.stdbss30.common.BizConsts;
import com.hp.bon.sgw.stdbss30.common.BizParam;

public class OutApiBizRouter {

	private static final Logger _log = LoggerFactory.getLogger(OutApiBizRouter.class);

	private Map<String, BizSlot> slotRepositories = new HashMap<String, BizSlot>();

	public void init() {
		
		/*******************************************************
		 * 对外计费3.0标准接口
		 */
		// 余额查询  QueryBalance.jf3
		BizSlot bizSlot = new QueryBalanceBizSlot();
		slotRepositories.put("QueryBalance.jf3", bizSlot);
		// 账户欠费查询 BillQueryOwe.jf3
		bizSlot = new BillQueryOweBizSlot();
		slotRepositories.put("BillQueryOwe.jf3", bizSlot);
		// 实时费用查询 RealFeeQuery.jf
		bizSlot = new RealFeeQueryBizSlot();
		slotRepositories.put("RealFeeQuery.jf3", bizSlot);
		// 充值缴费  Recharged.jf3
		bizSlot = new RechargedBizSlot();
		slotRepositories.put("Recharged.jf3", bizSlot);
		// 返销 RechargeRollback.jf3
		bizSlot = new RechargeRollbackBizSlot();
		slotRepositories.put("RechargeRollback.jf3", bizSlot);
		// 充值订单查询 RechargeQuery.jf3
		bizSlot = new RechargeQueryBizSlot();
		slotRepositories.put("RechargeQuery.jf3", bizSlot);
		// 操作流水查询 OperSerialQuery.jf3
		bizSlot = new OperSerialQueryBizSlot();
		slotRepositories.put("OperSerialQuery.jf3", bizSlot);
		// 缴费充值记录查询 PaymentRecordQuery.jf3
		bizSlot = new PaymentRecordQueryBizSlot();
		slotRepositories.put("PaymentRecordQuery.jf3", bizSlot);

		// 动态查询/断网查询  CommonDynQuery.jf3
		bizSlot = new CommonDynQueryBizSlot();
		slotRepositories.put("CommonDynQuery.jf3", bizSlot);

		// 话费返还记录查询ReturnBalance.jf3
		bizSlot = new ReturnBalanceBizSlot();
		slotRepositories.put("ReturnBalance.jf3", bizSlot);
		// 话费返还记录明细查询ReturnBalanceDetail.jf3
		bizSlot = new ReturnBalanceDetailBizSlot();
		slotRepositories.put("ReturnBalanceDetail.jf3", bizSlot);
		
		// 余额变动查询BalanceRecord.jf3
		bizSlot = new BalanceRecordBizSlot();
		slotRepositories.put("BalanceRecord.jf3", bizSlot);
		// 余额变动明细查询BalanceRecordDetail.jf3
		bizSlot = new BalanceRecordDetailBizSlot();
		slotRepositories.put("BalanceRecordDetail.jf3", bizSlot);
		
		// 天卡语音复网/20G断网复网  DayCardUnBlock.jf3
		bizSlot = new DayCardUnBlockSlot();
		slotRepositories.put("DayCardUnBlock.jf3", bizSlot);
		// 信用度查询  CreditQuery.jf3
		bizSlot = new CreditQuerySlot();
		slotRepositories.put("CreditQuery.jf3", bizSlot);
		// 信用度授予  CreditGive.jf3
		bizSlot = new CreditGiveSlot();
		slotRepositories.put("CreditGive.jf3", bizSlot);

		// 用户鉴权 ServAuth.jf3
		bizSlot = new ServAuthSlot();
		slotRepositories.put("ServAuth.jf3", bizSlot);
		// 紧急开机接口  EmergencyBoot.jf3
		bizSlot = new EmergencyBootSlot();
		slotRepositories.put("EmergencyBoot.jf3", bizSlot);
		
		/*******************************************************
		 * 对外计费其他接口
		 */
		// 用户归属地查询 QueryHomeAreaByAccNbr.HSS
		bizSlot = new QueryHomeAreaByAccNbrBizSlot();
		slotRepositories.put("QueryHomeAreaByAccNbr.HSS", bizSlot);
		// 用户鉴权QueryServ.HSS
		bizSlot = new QueryServBizSlot();
		slotRepositories.put("QueryServ.HSS", bizSlot);
		// 天卡套餐断网查询 CommonDynQuery.HB
		bizSlot = new CommonDynQueryHBBizSlot();
		slotRepositories.put("CommonDynQuery.HB", bizSlot);
		
		// 天卡语音复网 DayCardUnBlock.HB（DayCardUnBlock.WH）
		bizSlot = new DayCardUnBlockBizSlot();
		slotRepositories.put("DayCardUnBlock.HB", bizSlot);
		// 天卡语音复网 DayCardUnBlock.HB（DayCardUnBlock.WH）
		bizSlot = new DayCardUnBlockBizSlot();
		slotRepositories.put("DayCardUnBlock.WH", bizSlot);
		
		// 信用度查询  Query.CreditYXHB9(参考标准接口CreditQuery.jf3)
		bizSlot = new CreditQueryYXHB9BizSlot();
		slotRepositories.put("Query.CreditYXHB9", bizSlot);
		// 话费返还记录查询ReturnBalance.balanceYXHB9(参考标准接口ReturnBalance.jf3)
		bizSlot = new ReturnBalanceYXHB9BizSlot();
		slotRepositories.put("ReturnBalance.balanceYXHB9", bizSlot);
		// 话费返还记录明细查询ReturnBalanceDetail.balanceYXHB9(餐考标准接口ReturnBalanceDetail.jf3)
		bizSlot = new ReturnBalanceDetailYXHB9BizSlot();
		slotRepositories.put("ReturnBalanceDetail.balanceYXHB9", bizSlot);
		// 余额欠费查询 QryBalOwe.Bal(同时出现欠费和余额查询新接口返回)
		bizSlot = new QryBalOweBizSlot();
		slotRepositories.put("QryBalOwe.Bal", bizSlot);
		
		
		/*******************************************************
		 * 对外查询中心接口
		 */
		// 账单查询 BillDetailQuery.BillYXHB9
		bizSlot = new BillDetailQueryYXHB9BizSlot();
		slotRepositories.put("BillDetailQuery.BillYXHB9", bizSlot);

		// 银行代收费缴费  NormalPay.Payment
		bizSlot = new NormalPaySlot();
		slotRepositories.put("NormalPay.Payment", bizSlot);
	}

	public BizSlot doRouter(BizParam bizParam) {
		String capability = bizParam.getParamString(BizConsts.KEY_API_CAPABILITY);
		BizSlot bizSlot = slotRepositories.get(capability);
		if (null == bizSlot) {
			_log.error("none bizSlot,capability={}", capability);
			Set<Entry<String, BizSlot>> entries = slotRepositories.entrySet();
			for (Entry<String, BizSlot> entry : entries) {
				_log.info("bizSlot, key={}, clz={}", entry.getKey(), entry.getValue().getClass());
			}
		}
		return bizSlot;
	}

}
